package com.blog.study.study8;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * 〈Redis线程池工具类〉<br>
 *
 * @author 未绪
 * @time 2017/12/12 21:58
 */
public class JedisPoolUtils {

     private static volatile JedisPool jedisPool=null;

     private JedisPoolUtils(){
         throw new AssertionError("Error");
     }

     public static JedisPool getJedisPoolInstance(String host,Integer port){
         if(null == jedisPool){
             synchronized(JedisPoolUtils.class){
                 if(null == jedisPool){
                     JedisPoolConfig config=new JedisPoolConfig();
                     config.setMaxTotal(1000);
                     config.setMaxIdle(32);
                     config.setMaxWaitMillis(100*1000);
                     config.setTestOnBorrow(true);
                    jedisPool=new JedisPool(config,host,port);
                 }
             }
         }
         return jedisPool;
     }

     public static void release(JedisPool pool, Jedis jedis){

         if(null!=jedis){
             jedis.close();
         }

     }

}
